#ifndef UKUITASKBTN_H
#define UKUITASKBTN_H

#include <QToolButton>
#include <QGSettings/QGSettings>
#include <QMap>
#include "tasklist.h"

class QPainter;
class QPalette;
class QMimeData;
class QScrollArea;
class UKUITaskBar;

class QListWidget;
//UKUITaskBtn可能多个相同应用的叠加，如同时开启了多个终端
//多个应用窗口UKUIWindow对应一个UKUITaskBtn，一个UKUITaskBtn对应多个popup，一个popup对应一个应用窗口UKUIWindow

//这里的WaylandWindow应该是基于PlasmaWindow和kWindowSystem的一个抽象层，提供窗口的相关信息和动作调用(最大，最小等)
class UKUIWindow;
class UKUITaskbarPreviewWidget;

class UKUITaskBtn : public QToolButton
{
    Q_OBJECT
    Q_PROPERTY(QString appName READ appName WRITE setAppName)

public:
    explicit UKUITaskBtn(UKUIWindow *window, UKUITaskBar * taskbar,  QWidget *parent = 0);
    explicit UKUITaskBtn(QVector<UKUIWindow*> &windows, UKUITaskBar * taskbar,  QWidget *parent = 0);

    ~UKUITaskBtn();

    void setAppName(const QString &appName);
    QString appName() const;

    //当同一个应用多次打开时，再次增加window，但是taskbar上的窗口不再增加，taskview要增加
    void addWindowData(UKUIWindow *window);
    void removeWindowData(UKUIWindow *window);
    QVector<UKUIWindow*> getWindows();

    static QString mimeDataFormat() { return QLatin1String("ukui/UKUITaskButton"); }
    static bool isDraggging;

signals:
    void visibilityChanged(bool visible);
    void windowNumChanged();

    void dropped(QObject * dragSource, QPoint const & pos);
    void dragging(QObject * dragSource, QPoint const & pos);

protected:
    virtual void dragEnterEvent(QDragEnterEvent *event);
    virtual void dragMoveEvent(QDragMoveEvent * event);
    virtual void dragLeaveEvent(QDragLeaveEvent *event);
    virtual void dropEvent(QDropEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);

    QMimeData * mimeData();

    void showEvent(QShowEvent *event);
    void hideEvent(QHideEvent *event);

    void enterEvent(QEvent * event);
    void leaveEvent(QEvent * event);

    void contextMenuEvent(QContextMenuEvent * event);


public slots:
    void updateIcon();

private slots:
    void changeTaskButtonStyle();

    //update tasklist and position
    void updateTaskList();
    void updateTaskListPosition();
    //todo
    void updatePreviewList();


private:
    void init();
    UKUITaskbarPreviewWidget* createPreviewWidget(UKUIWindow* window);
    void showPreview();
    //当开始拖动时，隐藏预览级列表
    void hidePopUp();

    //从最终效果来看，Text并未更新？？
    void updateText(UKUIWindow* window);
    void updateIcon(UKUIWindow* window);
    //鼠标中键可以关闭当前窗口？
    void closeApplication();



    void showAllWindowByList();//when number of window is more than 30,need show all window of app by a list
    void showAllWindowByThumbnail();//when number of window is no more than 30,need show all window of app by a thumbnail



    enum TaskButtonStatus{NORMAL, HOVER, PRESS};
    TaskButtonStatus taskbuttonstatus;

    QVector<UKUIWindow*> m_windows;
    QMap<UKUIWindow*, UKUITaskbarPreviewWidget*> m_mapWindowPreview;

    UKUITaskBar *m_taskbar;
    QString m_appName;

    //QWidget *m_listWidget;
    TaskList *m_listWidget;
    QScrollArea *mpScrollArea;

    QPoint mDragStartPosition;

    bool m_bIconByClass;
};





#endif // UKUITASKBTN_H
